#include "kit/message/Message.hpp"
#include <vector>
#include <sstream>
#include "kit/tool/Tokenizer.hpp"

namespace KitMessage
{
	void Message::decode()
	{
		// remove the new line character from the end
		std::string aPayload = _payload.substr(0, _payload.size() - 1);
		// split into tokens
		std::vector<std::string> tokens = KitTool::Tokenizer::tokenize(aPayload, '|');
		// assign _sequenceNo
		std::stringstream ss;
		ss << tokens[0];
		ss >> _sequenceNo;
		// assign _type
		_type = tokens[1];
		// assign from, if received
		if(tokens.size() >= 3)
			_from = tokens[2];
		// assign to, if received
		if(tokens.size() >= 4)
			_to = tokens[3];
	}
}



